using System.Collections.Generic;
using AdvancedInspector;
using UnityEngine;

[AdvancedInspector(true)]
public class ChestBonusItem
{
	public string linkKey;

	public bool isVisible;

	public List<ChestTir> tirs;

	public int CurrentLevel
	{
		get
		{
			int num = 0;
			if (ProtectedPrefs.CryptoKeyIntCorrect(settings.keyCurLevel))
			{
				return Load.LoadInt(settings.keyCurLevel) + 1;
			}
			return 0;
		}
	}

	public ChestTir GetChestTirForCurrentLevel()
	{
		int currentLevel = CurrentLevel;
		for (int num = tirs.Count - 1; num >= 0; num--)
		{
			if (tirs[num].startLevel <= currentLevel)
			{
				return tirs[num];
			}
		}
		return null;
	}

	public string GetItemCountOrTime()
	{
		ChestTir chestTirForCurrentLevel = GetChestTirForCurrentLevel();
		if (chestTirForCurrentLevel == null || chestTirForCurrentLevel.items == null || chestTirForCurrentLevel.items.Count == 0)
		{
			return string.Empty;
		}
		if (chestTirForCurrentLevel.items.Count == 1)
		{
			return chestTirForCurrentLevel.items[0].GetItemCountOrTime();
		}
		return string.Empty;
	}

	public Texture GetImage()
	{
		ChestTir chestTirForCurrentLevel = GetChestTirForCurrentLevel();
		if (chestTirForCurrentLevel == null || chestTirForCurrentLevel.items == null || chestTirForCurrentLevel.items.Count == 0)
		{
			return null;
		}
		string empty = string.Empty;
		if (chestTirForCurrentLevel.items.Count == 1)
		{
			ChestBonusItemData chestBonusItemData = chestTirForCurrentLevel.items[0];
			return chestBonusItemData.GetTexture();
		}
		return null;
	}

	public void ClearTirs()
	{
		foreach (ChestTir tir in tirs)
		{
			tir.items.Clear();
		}
		tirs.Clear();
	}
}
